//
//  BMAMovieViewController.m
//  Autismus
//
//  Created by Salhi yacine on 03/12/11.
//  Copyright (c) 2011 EPITECH. All rights reserved.
//

#import "BMAMovieViewController.h"

@implementation BMAMovieViewController

@synthesize mp, delegateIntru;

- (id)initWithPath:(NSString *)moviePath
{
    if (self = [super init])
    {
        DLOG(@"%@", moviePath);
        
        self.mp =  [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
        
        //[self.mp setShouldAutoplay:YES];
        
        self.mp.scalingMode = MPMovieScalingModeAspectFill;
        self.mp.controlStyle = MPMovieControlStyleNone;
        self.mp.view.frame = CGRectMake(0, 0, 1024, 768);
        self.mp.movieSourceType = MPMovieSourceTypeFile;
        
        [self.view addSubview:self.mp.view];
        
        //[self.mp setFullscreen:YES animated:YES];
        
        // Register to receive a notification when the movie has finished playing. 
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(moviePlayBackDidFinish:) 
                                                     name:MPMoviePlayerPlaybackDidFinishNotification 
                                                   object:nil];
        
        [self.mp play];
    }
    
    return self;
}

-(void)moviePlayBackDidFinish:(id)sender
{
    [delegateIntru nextExercice];
    [self dismissModalViewControllerAnimated:YES];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
	return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

@end
